package com.yanqu.road.server.cmd.activity.jiuzhou;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.jiuzhou.JiuZhouProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jiuzhou.JiuZhouModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_JIU_ZHOU_GET_BASE_DATA, desc = "拉取九州活动游戏服基础数据")
public class JiuZhouGetGameBaseDataCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JiuZhouProto.GetBaseJiuZhouUserDataReqMsg getBaseJiuZhouUserDataReqMsg = JiuZhouProto.GetBaseJiuZhouUserDataReqMsg.parseFrom(packet.getBytes());
        activityId = getBaseJiuZhouUserDataReqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(JiuZhouModule.class).getUserBaseData(activityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            JiuZhouProto.GetBaseJiuZhouUserDataRespMsg.Builder respMsg = JiuZhouProto.GetBaseJiuZhouUserDataRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_JIU_ZHOU_GET_BASE_DATA, respMsg);

        }
    }
}
